package com.amos.bean;

import lombok.Data;

import java.io.Serializable;

/**
 * Copyright © 2018 五月工作室. All rights reserved.
 *
 * @Package com.amos.bean
 * @ClassName Result
 * @Description TODO
 * @Author Amos
 * @Modifier
 * @Date 2020/3/8 21:49
 * @Version 1.0
 **/
@Data
public class Result implements IResult, Serializable {

    private static final long serialVersionUID = -2178684279947338862L;
    /**
     * 成功
     */
    public static final Integer SUCCESS = 200;
    /**
     * 校验失败
     */
    public static final Integer VALIDATE_ERROR = 401;
    /**
     * 系统异常
     */
    public static final Integer ERROR = 500;
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 消息
     */
    private String msg;
    /**
     * 数据
     */
    private Object data;

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static Result success(Object data) {
        return new Result(SUCCESS, "成功", data);
    }

    public static Result ok() {
        return new Result(SUCCESS, "成功", null);
    }

    public static Result error(String msg) {
        return new Result(ERROR, msg, null);
    }

    public static Result fail(String msg) {
        return new Result(VALIDATE_ERROR, msg, null);
    }

    public static Result fail(String msg, Object data) {
        return new Result(VALIDATE_ERROR, msg, data);
    }
}

